package cn.cew.bytespyserver.controller;


import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotEmpty;
import java.util.Arrays;
import java.util.List;

/**
 * @author chenenwei
 * @version 1.0.0
 * @description TODO
 * @createTime 2022-10-15 13:33:00
 */
@Data
public class CmdParam {

    @ApiModelProperty("进程ID")
    @NotEmpty(message = "进程ID不能为空")
    private String pid;

    @ApiModelProperty("ip")
    @NotEmpty(message = "ip不能为空")
    private String ip;

    @ApiModelProperty("端口")
    private int port;

    @ApiModelProperty(value = "目标jar包绝对路径", example = "c:/test.jar")
    @NotEmpty(message = "jar包不能为空")
    private String jarFile;

    @ApiModelProperty(value = "操作类型,多个逗号隔开", example = "1,2")
    @NotEmpty(message = "操作类型不能为空")
    private String operator;

    @ApiModelProperty(value = "类型", example = "1")
    @NotEmpty(message = "操作类型不能为空")
    private String type;

    @ApiModelProperty("包名")
    @NotEmpty(message = "包名不能为空")
    private String packageName;

    @ApiModelProperty("类名")
    @NotEmpty(message = "类名不能为空")
    private String className;

    @ApiModelProperty("方法名称")
    @NotEmpty(message = "方法名称不能为空")
    private String methodName;

    @ApiModelProperty(value = "还原类", example = "true")
    private boolean recover;

    @ApiModelProperty("创建代理类")
    private boolean createProxy = true;

    @ApiModelProperty(value = "代码行", example = "System.out.println(this.getCmd());")
    private String lineCode;

    @ApiModelProperty(value = "方法体", example = "public String getCmd () { return \"test\"; }")
    private String methodBody;

    @ApiModelProperty(value = "导入的包，多个逗号隔开", example = "java.lang.lang,java.lang.Integer")
    private String importPackages;

    @ApiModelProperty(value = "方法签名", example = "([Ljava/lang/String;)V")
    @NotEmpty(message = "进程ID不能为空")
    private String signature;

    @ApiModelProperty(value = "局部变量名称,多个逗号隔开", example = "a,b")
    private String localVars;

    @ApiModelProperty(value = "全局变量名称,多个逗号隔开", example = "a,b")
    private String globalVars;

    public String getCmd () {

        StringBuilder builder = new StringBuilder();
        builder.append("ip").append(":").append(ip).append("@")
                .append("port").append(":").append(port).append("@")
                .append("type").append(":").append(type).append("@")
                .append("operator").append(":").append(operator).append("@")
                .append("globalVars").append(":").append(globalVars).append("@")
                .append("localVars").append(":").append(localVars).append("@")
                .append("pName").append(":").append(packageName).append("@")
                .append("cName").append(":").append(className).append("@")
                .append("mName").append(":").append(methodName).append("@")
                .append("recover").append(":").append(recover).append("@")
                .append("proxy").append(":").append(createProxy).append("@")
                .append("lCode").append(":").append(lineCode).append("@")
                .append("mBody").append(":").append(methodBody).append("@")
                .append("packages").append(":").append(getImportPackages()).append("@")
                .append("signature").append(":").append(signature);
        return builder.toString();
    }
}

